package _2022.contest.biweekly.biweekly_contest_75;


/**
 * @author： YHSimon
 * @date： 2022-04-02 22:33
 */
public class Solution1 {
    public int minBitFlips(int start, int goal) {
        int res = 0;
        String startStr = Integer.toBinaryString(start);
        String goalStr = Integer.toBinaryString(goal);
        int i = startStr.length() - 1, j = goalStr.length() - 1;
        while (j >= 0 && i >= 0) {
            if (goalStr.charAt(j) != startStr.charAt(i)) {
                res++;
            }
            j--;
            i--;
        }
        while (j >= 0) {
            if (goalStr.charAt(j) == '1') {
                res++;
            }
            j--;
        }
        while (i >= 0) {
            if (startStr.charAt(i) == '1') {
                res++;
            }
            i--;
        }
        return res;
    }

    public static void main(String[] args) {
        Solution1 s = new Solution1();
        System.out.println(s.minBitFlips(7, 10));

    }
}
